package org.csu.wuliu.service;

import org.csu.wuliu.domain.*;
import org.csu.wuliu.persistence.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class SubstationService {

    @Autowired
    private SignMapper signMapper;

    @Autowired
    private TaskMapper taskMapper;

    @Autowired
    private DistributorMapper distributorMapper;

    @Autowired
    private PayMapper payMapper;

    @Autowired
    private RefundMapper refundMapper;

    @Autowired
    private ReceiptMapper receiptMapper;

    @Autowired
    private SubstationMapper substationMapper;

    //-----------------------------TaskService-------------------------

    public List<Task> getTaskList(@RequestParam("substationId") String substationId){
        List<Task> taskList = taskMapper.getTaskListBySubstation(substationId);
        return taskList;
    }

    public Task getTaskByTaskId(String taskId){
        return taskMapper.getTaskByTaskId(taskId);
    }

    public Task updateTask(Task task){
        taskMapper.updateTask(task);
        return task;
    }

    public List<Task> getTaskListByDistributorId(String distributorId){
        return taskMapper.getTaskListByDistributorId(distributorId);
    }

    public List<Task> getTaskListBySubstation(String substationId){
        return taskMapper.getTaskListBySubstation(substationId);
    }


    //---------------------------SignService---------------------------

    public Sign getSignByTaskId(String taskId){
        return signMapper.getSignByTaskId(taskId);
    }

    public void insertSign(Sign sign){
        signMapper.insertSign(sign);
    }


    //--------------------------DistributorService---------------------

    public Distributor getDistributor(String distributorId){
        return distributorMapper.getDistributor(distributorId);
    }

    public List<Distributor> getDistributorListBySubstationId(String substationId){
        return distributorMapper.getDistributorListBySubstationId(substationId);
    }
    //-------------------------MoneyManageService----------------------

    public List<Pay> getPayListBySubstationIdAndMonth(String yearmonth,String substationId){
        return payMapper.getPayListBySubstationIdAndMonth(yearmonth,substationId);
    }

    public List<Refund> getRefundListBySubstationIdAndMonth(String yearmonth,String substationId){
        return refundMapper.getRefundListBySubstationIdAndMonth(yearmonth,substationId);
    }

    //-------------------------ReceiptService

    public Receipt getReceiptByTaskId(String taskId){
        return receiptMapper.getReceiptByTaskId(taskId);
    }

    public void insertReceipt(Receipt receipt){
        receiptMapper.insertReceipt(receipt);
    }

    //------------------------SubstationService
    public Substation getSubstaionByAddress(String address){
        return substationMapper.getSubstationByAddress(address + "%");
    }

    public List<Substation> getSubstationList(){
        return substationMapper.getSubstationList();
    }
}
